package com.ruoyi.web.controller.suggestion;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.suggestion.domain.CommunityVote;
import com.ruoyi.suggestion.service.ICommunityVoteService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 建议投票Controller
 * 
 * @author xianyu
 * @date 2025-04-03
 */
@RestController
@RequestMapping("/suggestion/vote")
public class CommunityVoteController extends BaseController
{
    @Autowired
    private ICommunityVoteService communityVoteService;

    /**
     * 查询建议投票列表
     */
    @PreAuthorize("@ss.hasPermi('suggestion:vote:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityVote communityVote)
    {
        startPage();
        List<CommunityVote> list = communityVoteService.selectCommunityVoteList(communityVote);
        return getDataTable(list);
    }

    /**
     * 导出建议投票列表
     */
    @PreAuthorize("@ss.hasPermi('suggestion:vote:export')")
    @Log(title = "建议投票", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunityVote communityVote)
    {
        List<CommunityVote> list = communityVoteService.selectCommunityVoteList(communityVote);
        ExcelUtil<CommunityVote> util = new ExcelUtil<CommunityVote>(CommunityVote.class);
        util.exportExcel(response, list, "建议投票数据");
    }

    /**
     * 获取建议投票详细信息
     */
    @PreAuthorize("@ss.hasPermi('suggestion:vote:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(communityVoteService.selectCommunityVoteById(id));
    }

    /**
     * 新增建议投票
     */
    @PreAuthorize("@ss.hasPermi('suggestion:vote:add')")
    @Log(title = "建议投票", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityVote communityVote)
    {
        return toAjax(communityVoteService.insertCommunityVote(communityVote));
    }

    /**
     * 修改建议投票
     */
    @PreAuthorize("@ss.hasPermi('suggestion:vote:edit')")
    @Log(title = "建议投票", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityVote communityVote)
    {
        return toAjax(communityVoteService.updateCommunityVote(communityVote));
    }

    /**
     * 删除建议投票
     */
    @PreAuthorize("@ss.hasPermi('suggestion:vote:remove')")
    @Log(title = "建议投票", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(communityVoteService.deleteCommunityVoteByIds(ids));
    }
}
